package 算法;

public class _01问题 {
    public static void main(String[] args) {
        System.out.println(new _01问题().findMaxForm(new String[]{"10", "0001", "111001", "1", "0"},5,3));
    }
    //m个0，n个1
    public int findMaxForm(String[] strs, int m, int n) {
        int[][] bg = new int[m+1][n+1];
        for (String str : strs) {
            int[] charLen = coun(str);
            for (int i = m;i >= charLen[0];i--){
                for (int j = n; j >= charLen[1]; j--){
                    bg[i][j] = Math.max(bg[i][j],1+bg[i-charLen[0]][j-charLen[1]]);
                }
            }
        }
        return bg[m][n];
    }
    public int[] coun(String str){
        int[] co = new int[2];
        for(int i = 0;i < str.length(); i++){
            if(str.charAt(i) == '0'){
                co[0]++;
            }else {
                co[1]++;
            }
        }
        return co;
    }
}
